<?php
// +----------------------------------------------------------------------
// | Created by PHPstorm: [ JRK丶Admin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/6/26 0026
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------

namespace app\admin\controller;


use app\common\controller\AdminBaseController;
use app\common\model\tang\CostRule;
use app\common\model\tang\Merchant as MerchantModel;
use app\common\model\tang\ApiInfo as CostModel;
use app\common\model\tang\CostType;
use app\common\model\tang\StaffRule;
use app\common\model\tang\SubjectList;
use think\facade\Config;
use think\facade\Db;

class Loss extends AdminBaseController
{
    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->model = new CostModel();
    }

    public function index()
    {
        if (IS_AJAX){
            $data = $this->request->post();
            Db::startTrans();
            try {
                unset($data['__token__']);
                unset($data['date']);
                unset($data['file']);
                if($data['id']){
                    $info = $this->model->find($data['id']);
                    $info->save($data);
                }else{
                    $this->model->save($data);
                }
                Db::commit();
                return self::JsonReturn("添加成功");
            }catch (\Exception $exception){
                Db::rollback();
                return self::JsonReturn($exception->getMessage(),0);
            }
        }
        $info = $this->model->find(1);
        $this->assign(compact("info" ));
        return $this->fetch();
    }

}